--region *.lua
--Date
--此文件由[BabeLua]插件自动生成\
local WelcomeScene = {}
local scheduler = cc.Director:getInstance():getScheduler()
local landHeight = 0
local landScheduler = 0

local function spriteLayer()
	local layer = cc.Layer:create()

	local b = cc.exports.createBird()
	b.addSwing()
	local bird = b.getBird()
	bird:setPosition(cc.p(display.cx, display.cy + bird:getContentSize().height / 2))
	bird:addTo(layer)
	
	local l = cc.exports.createLand()
	local land1, land2 = l.getLands()
	landHeight = land1:getContentSize().height
	landScheduler = scheduler:scheduleScriptFunc(l.setScroll, SPEED.MAP_SCROLL, false)
	land1:addTo(layer)
	land2:addTo(layer)
	return layer
end

local function bgLayer()
	local layer = cc.Layer:create();

	local title = cc.Sprite:create("title.png")
	title:setPosition(display.cx, display.cy + title:getContentSize().height * 2)
	title:addTo(layer)

	local brand = cc.Sprite:create("brand_copyright.png")
	brand:setAnchorPoint(0.5, 1)
	brand:setPosition(display.cx, 
					display.cy - bgHeight / 2 + landHeight - brand:getContentSize().height * 1.5)
	brand:addTo(layer)

	return layer
end

local function menuLayer()
	local layer = cc.Layer:create()
	
	local menu = cc.Menu:create()
	local rate = cc.MenuItemImage:create("button_rate.png", "button_rate.png")
	rate:addTo(menu)
   
	local play = cc.MenuItemImage:create("button_play.png","button_play.png")
	play:setName(SCENE.READY)
	local function replace(name, sender)
	    local name = sender:getName()
	    local r = require("app.views.scene."..name)
	    local director = cc.Director:getInstance()
	    director:getScheduler():unscheduleScriptEntry(landScheduler)
	    director:replaceScene(r.create())
	end
	play:registerScriptTapHandler(replace)    
	play:addTo(menu)

	local score = cc.MenuItemImage:create("button_score.png","button_score.png")
	score:addTo(menu)
	menu:setPosition(cc.p(0, 0))
   
	local x, y = display.cx, display.cy - rate:getContentSize().height
	rate:setPosition(cc.p(x, y))

	x = display.cx-play:getContentSize().width/2
	y = display.cy-play:getContentSize().height-rate:getContentSize().height
	play:setPosition(cc.p(x, y))

	x = display.cx+score:getContentSize().width/2
	y = display.cy-score:getContentSize().height-rate:getContentSize().height
	score:setPosition(cc.p(x, y))

	menu:addTo(layer)
	return layer
end


function WelcomeScene.create()
	local scene = cc.Scene:create()
	local bg = display.newSprite("bg_day.png")
	bg:move(display.center)
	bg:addTo(scene, BGz, TAG.BG)
	cc.exports.bgWidth = bg:getContentSize().width
	cc.exports.bgHeight = bg:getContentSize().height

	scene:addChild(spriteLayer(), SPRITEz)
	scene:addChild(bgLayer(), FONTz)
	scene:addChild(menuLayer(), MENUz)

	scene = cc.TransitionFade:create(0.3, scene)
	return scene
end
return WelcomeScene
--endregion
